package androidx.preference;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.appcompat.app.b;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.c;
import androidx.fragment.app.d;
import androidx.preference.DialogPreference;

public abstract class f extends c implements DialogInterface.OnClickListener {
    private DialogPreference p;
    private CharSequence q;
    private CharSequence r;
    private CharSequence s;
    private CharSequence t;
    private int u;
    private BitmapDrawable v;
    private int w;

    private void r(Dialog dialog) {
        dialog.getWindow().setSoftInputMode(5);
    }

    public Dialog h(Bundle bundle) {
        d activity = getActivity();
        this.w = -2;
        b.a aVar = new b.a(activity);
        aVar.t(this.q);
        aVar.f(this.v);
        aVar.p(this.r, this);
        aVar.k(this.s, this);
        View o = o(activity);
        if (o != null) {
            n(o);
            aVar.u(o);
        } else {
            aVar.h(this.t);
        }
        q(aVar);
        b a2 = aVar.a();
        if (m()) {
            r(a2);
        }
        return a2;
    }

    public DialogPreference l() {
        if (this.p == null) {
            this.p = (DialogPreference) ((DialogPreference.a) getTargetFragment()).findPreference(getArguments().getString("key"));
        }
        return this.p;
    }

    /* access modifiers changed from: protected */
    public boolean m() {
        return false;
    }

    /* access modifiers changed from: protected */
    public void n(View view) {
        View findViewById = view.findViewById(16908299);
        if (findViewById != null) {
            CharSequence charSequence = this.t;
            int i = 8;
            if (!TextUtils.isEmpty(charSequence)) {
                if (findViewById instanceof TextView) {
                    ((TextView) findViewById).setText(charSequence);
                }
                i = 0;
            }
            if (findViewById.getVisibility() != i) {
                findViewById.setVisibility(i);
            }
        }
    }

    /* access modifiers changed from: protected */
    public View o(Context context) {
        int i = this.u;
        if (i == 0) {
            return null;
        }
        return getLayoutInflater().inflate(i, (ViewGroup) null);
    }

    public void onClick(DialogInterface dialogInterface, int i) {
        this.w = i;
    }

    public void onCreate(Bundle bundle) {
        BitmapDrawable bitmapDrawable;
        super.onCreate(bundle);
        Fragment targetFragment = getTargetFragment();
        if (targetFragment instanceof DialogPreference.a) {
            DialogPreference.a aVar = (DialogPreference.a) targetFragment;
            String string = getArguments().getString("key");
            if (bundle == null) {
                DialogPreference dialogPreference = (DialogPreference) aVar.findPreference(string);
                this.p = dialogPreference;
                this.q = dialogPreference.I0();
                this.r = this.p.K0();
                this.s = this.p.J0();
                this.t = this.p.H0();
                this.u = this.p.G0();
                Drawable F0 = this.p.F0();
                if (F0 == null || (F0 instanceof BitmapDrawable)) {
                    bitmapDrawable = (BitmapDrawable) F0;
                } else {
                    Bitmap createBitmap = Bitmap.createBitmap(F0.getIntrinsicWidth(), F0.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
                    Canvas canvas = new Canvas(createBitmap);
                    F0.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
                    F0.draw(canvas);
                    bitmapDrawable = new BitmapDrawable(getResources(), createBitmap);
                }
                this.v = bitmapDrawable;
                return;
            }
            this.q = bundle.getCharSequence("PreferenceDialogFragment.title");
            this.r = bundle.getCharSequence("PreferenceDialogFragment.positiveText");
            this.s = bundle.getCharSequence("PreferenceDialogFragment.negativeText");
            this.t = bundle.getCharSequence("PreferenceDialogFragment.message");
            this.u = bundle.getInt("PreferenceDialogFragment.layout", 0);
            Bitmap bitmap = (Bitmap) bundle.getParcelable("PreferenceDialogFragment.icon");
            if (bitmap != null) {
                this.v = new BitmapDrawable(getResources(), bitmap);
                return;
            }
            return;
        }
        throw new IllegalStateException("Target fragment must implement TargetFragment interface");
    }

    public void onDismiss(DialogInterface dialogInterface) {
        super.onDismiss(dialogInterface);
        p(this.w == -1);
    }

    public void onSaveInstanceState(Bundle bundle) {
        super.onSaveInstanceState(bundle);
        bundle.putCharSequence("PreferenceDialogFragment.title", this.q);
        bundle.putCharSequence("PreferenceDialogFragment.positiveText", this.r);
        bundle.putCharSequence("PreferenceDialogFragment.negativeText", this.s);
        bundle.putCharSequence("PreferenceDialogFragment.message", this.t);
        bundle.putInt("PreferenceDialogFragment.layout", this.u);
        BitmapDrawable bitmapDrawable = this.v;
        if (bitmapDrawable != null) {
            bundle.putParcelable("PreferenceDialogFragment.icon", bitmapDrawable.getBitmap());
        }
    }

    public abstract void p(boolean z);

    /* access modifiers changed from: protected */
    public void q(b.a aVar) {
    }
}
